package com.finley.flowabledemo.plc.service;

import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
import org.springframework.stereotype.Service;

@Service
public class S7Service {

    private final S7PLC s7PLC;

    public S7Service(S7PLC s7PLC) {
        this.s7PLC = s7PLC;
    }

    /**
     * 读取布尔值
     * @param address 地址(如 "DB2.0.7" 或 "Q0.7")
     * @return 布尔值
     */
    public boolean readBoolean(String address) {
        return s7PLC.readBoolean(address);
    }

    /**
     * 读取字节
     * @param address 地址(如 "DB2.1")
     * @return 字节值
     */
    public byte readByte(String address) {
        return s7PLC.readByte(address);
    }

    /**
     * 读取16位无符号整数
     * @param address 地址
     * @return 16位无符号整数
     */
    public int readUInt16(String address) {
        return s7PLC.readUInt16(address);
    }

    /**
     * 读取32位浮点数
     * @param address 地址
     * @return 32位浮点数
     */
    public float readFloat32(String address) {
        return s7PLC.readFloat32(address);
    }

    /**
     * 写入布尔值
     * @param address 地址
     * @param value 要写入的值
     */
    public void writeBoolean(String address, boolean value) {
        s7PLC.writeBoolean(address, value);
    }

    /**
     * 写入字节
     * @param address 地址
     * @param value 要写入的值
     */
    public void writeByte(String address, byte value) {
        s7PLC.writeByte(address, value);
    }

    /**
     * 写入16位无符号整数
     * @param address 地址
     * @param value 要写入的值
     */
    public void writeUInt16(String address, int value) {
        s7PLC.writeUInt16(address, value);
    }

    /**
     * 写入32位浮点数
     * @param address 地址
     * @param value 要写入的值
     */
    public void writeFloat32(String address, float value) {
        s7PLC.writeFloat32(address, value);
    }
}